All Questions
Tagged with object-oriented-designrefactoring
31 questions
4votes
3answers
253views
How do you handle instantiating a large number of interconnected component objects?
I'm currently refactoring our instance startup code, which is currently a 2,000 line mud method. The issue is that that method needs to create a large number (>50) of components/service objects, ...
0votes
2answers
343views
How to refactor this tightly-coupled method and (mostly) preserve its encapsulation?
I have recently encountered this problematic method (minimal reproducible sample in C++ but this question aims to be language agnostic past the syntax): void MyObject::twice_bind_cycle() { _bind1()...
0votes
4answers
320views
Object matching using generic method? [closed]
I have a piece of code where two objects (incoming request object and a profile object) are to be checked for matching conditions. So the first method is as below where I check whether the profile ...
1vote
2answers
269views
Anemic Domain Model VS coupling and dependencies- design conflict - need an Object oriented advice
on design stage , after finding my main objects , I am always find my self writing "manager" or "controllers" classes in order to handle the connection between them. some of the ...
1vote
2answers
651views
No trivial god-class refactoring
Consider you have the following code: class UserContainer { List<User> user; //some methods to get specific users, for example users, which are higher than 1,70meters } The User have a ...
3votes
3answers
836views
Use inheritance to make single child, smaller
We have a relatively big class. One of my colleagues thinks we must split this class into a base & child class to make it smaller and cleaner. On the other hand, I believe when we know this parent ...
18votes
9answers
5kviews
Which object should have the method?
I am trying to create an object model for a user and a chatroom. I'm stuck on where to place certain functionality when the objects collaborate. At the moment all the functionality for the User is ...
99votes
9answers
19kviews
Is it the correct practice to keep more than 10 years old spaghetti legacy code untouched without refactoring at all in big product development?
I have been in two software product houses for three years in a row. The first is a small company maintaining a fairly small management system with a monolithic legacy code base (almost twenty years). ...
1vote
3answers
220views
Approach for rewriting a large, mission-critical method
Context: I am a new hire out of university at a large software company tasked with either refactoring or re-writing a large legacy method (~500 lines, ~2000 lines expanded with private method calls) ...
2votes
2answers
938views
Large method with nested switch case(s) refactoring (Java)
Essentially I've got a bunch of formulas in two giant methods in a class designed to do math transformations and evaluations to multiple inputs. Where the inputs are actually lists of inputs (as there ...
-3votes
1answer
208views
Different input param for the same logic flow
I'm trying to find the best design approach to handle a design change in a new project I'm working on. At the moment, the flow runs and makes some calculations based on a parameter which is used. ...
-2votes
4answers
356views
Is judicious & plausible selection of class fields a valid refactoring step?
I'm a great fan of refactoring but I've been wondering about the issues raised by refactoring. Fowler advises refactoring to make code readable to all users to make the code structure more sensible, ...
7votes
2answers
494views
How to avoid changing dozens of classes and interfaces when adding an argument to a method used in dozens of classes and interfaces?
On several occasions, I was faced with the following design issue that I don't know how to resolve. Imagine, for instance, an application which at some point receives a JSON object from an API. Before ...
1vote
1answer
171views
How to add supporting information to the existing java object?
Is there a way or design pattern to add supporting information to the existing java object? Example I have a model class Parent and it has child models. Its nothing but hibernate entities with parent-...
1vote
2answers
453views
Encapsulation and input validation duplication
Consider the following example (very simplified): public class Basket { private readonly List<BasketItem> _items = new List<BasketItem>(); public IReadOnlyCollection<BasketItem&...